#!/bin/sh

which pkg-config ||
{
	echo "Command not found: pkg-config"
	exit 1
}

pkg-config --libs hiredis || exit 1

[ -f "Makefile" -a "$1" = "debug" ] ||
{
	./configure --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --prefix=/usr --conf-path=/etc/nginx/nginx.conf || exit 1
}

make -j4 || exit 1
sudo make install || exit 1

echo "Install successfull"

[ "$1" = "debug" ] &&
{
	sudo killall nginx

	for fn in error.log access.log
	do
		sudo rm -rfv "/usr/logs/${fn}"
	done

	sudo nginx && echo "Restart nginx success"
}
